<!DOCTYPE html>
<html>
<head>
    <meta name="layout" content="main"/>
    <g:set var="entityName" value="${message(code: 'estate.label', default: 'estate')}"/>
    <title>数据字典</title>
    <style>
    .table-bordered>thead>tr>td, .table-bordered>thead>tr>th{
        border-bottom-width: 1px;
    }
    </style>
</head>

<body class="fixed-navbar fixed-sidebar">

<div class="small-header">
    <div class="hpanel">
        <div class="panel-body">
            <div id="hbreadcrumb" class="pull-right">
                <ol class="hbreadcrumb breadcrumb">
                    <li>CINDATA PLS</li>
                    <li class="active">
                        <span>数据字典</span>
                    </li>
                </ol>
            </div>

            <h2 class="font-light m-b-xs">
                <span>数据字典</span>
            </h2>
        </div>
    </div>
</div>

<div class="content animate-panel">

    %{--tab切换--}%



    <div class="row">
        <div class="hpanel hgreen" style="">
            <div class="panel-heading">
                <div class="panel-tools">
                    <a href="#" class="estateRiskBtn btn btn-info btn-xs"
                       type-dic="${this?.dimension}"
                       data-toggle="modal" data-target="#add1">新增</a>
                    <a class="showhide"><i class="fa fa-chevron-up"></i></a>
                </div>
                &nbsp;
            </div>

            <div class="panel-body">

                <ul class="nav nav-tabs">
                    <g:each status="i" in="${this.dictoryMap.entrySet()}" var="entry">
                        <li <g:if test="${this?.dimension == entry?.key}">class="active"</g:if></li>
                        <g:link controller="customerDimension" action="index" id="${entry?.key}">
                            ${entry?.value}
                        </g:link>
                        </li>
                    </g:each>
                </ul>
                <div class="tab-content">
                    <div id="tab-1" class="tab-pane active">
                        <div class="panel-body" style="border:none;padding: 0;">
                            <div class="tab-pane fade in active">
                                <table cellpadding="1" cellspacing="1" class="table table-striped table-bordered table-hover text-center">
                                    <thead>
                                    <td class="text-center"><b>序号</b></td>
                                    <td class="text-left" style="padding-left: 20%;"><b>字段名</b></td>
                                    <td class="text-left" style="padding-left: 20%;"><b>操作</b></td>
                                    </thead>
                                    <tbody>
                                    <g:each in="${this.primaryDimensionList.entrySet()}" var="entry">
                                        <g:each status="i" in="${primaryDimensionList.get(entry.key)}" var="it">
                                            <tr>
                                                <td class="text-center"><a class="btn btn-info btn-xs">1</a></td>
                                                <td class="text-left" style="padding-left: 20%;">${it?.label}</td>
                                                <td class="text-left" style="padding-left: 20%;">
                                                    <a href="#" data-toggle="modal" class="new_btn btn btn-info btn-xs"
                                                       data-target="#add2" data-id="${it?.id}">新增</a>
                                                    <a href="#" data-toggle="modal" class="modify_btn btn btn-info btn-xs"
                                                       data-target="#upd1"
                                                       data-id="${it?.id}" data-label="${it?.label}"
                                                       order-number="${it?.orderNumber}"
                                                       data-code="${it?.code}">修改</a>
                                                    <a href="#" data-toggle="modal" class="delDimen btn btn-info btn-xs"
                                                       data-target="#del1" data-id="${it?.id}">删除</a>
                                                </td>

                                            </tr>
                                            <g:each in="${secondaryDimensionList}" var="sd">
                                                <g:if test="${sd?.parent?.id == it?.id}">
                                                    <tr>
                                                        <td class="text-center"><a class="btn btn-info btn-xs"
                                                                                   style="background: skyblue">2</a></td>
                                                        <td class="text-left" style="padding-left: 20%;">${sd?.label}</td>
                                                        <td class="text-left" style="padding-left: 20%;">
                                                            <a href="#" data-toggle="modal"
                                                               class="s_modify_btn btn btn-info btn-xs"
                                                               data-target="#upd2"
                                                               data-id="${sd?.id}" data-label="${sd?.label}"
                                                               order-number="${sd?.orderNumber}"
                                                               minValue="${sd?.minValue}" maxValue="${sd?.maxValue}"
                                                               maxOperator="${sd?.maxOperator}"
                                                               minOperator="${sd?.minOperator}"
                                                               define="${sd?.define}">修改</a>
                                                            <a href="#" data-toggle="modal"
                                                               class="s-delDimen btn btn-info btn-xs"
                                                               data-target="#del2" data-id="${sd?.id}">删除</a>
                                                        </td>

                                                    </tr>
                                                </g:if>
                                            </g:each>
                                        </g:each>
                                    </g:each>
                                    </tbody>
                                </table>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

        </div>
    </div>

    %{--弹框1--}%
    <div class="content animate-panel p-b-n">
        <div class="row">
            <div class="hpanel">
                <div class="modal fade hmodal-info" id="add1" tabindex="-1" role="dialog" aria-hidden="true">
                    <div class="modal-dialog">
                        <div class="modal-content">
                            <div class="color-line"></div>

                            <div class="modal-header">
                                <h4 class="modal-title"><span id="title">添加一级参数</span><small style="font-size: 14px"
                                                                                             class="font-bold">(注：<span
                                            style="color: red">*</span> 为必填)</small></h4>
                            </div>

                            <form class="form-horizontal" name="add1" id="add1form">
                                <div class="modal-body form-horizontal">

                                    <input type="hidden" name="dictoryType" id="dictoryType" value="">

                                    <div class="form-group">
                                        <label class="col-md-2 control-label is-required">标签</label>

                                        <div class="col-md-4">
                                            <g:textField class="form-control" type="text" name="label" id="label1"
                                                         value=""/>
                                        </div>

                                        <label class="col-md-2 control-label is-required">排序</label>

                                        <div class="col-md-4">
                                            <g:textField class="form-control" type="text" name="orderNumber"
                                                         id="order1" value=""/>
                                        </div>
                                    </div>

                                    <div class="form-group">
                                        <label class="col-md-2 control-label is-required">唯一代码</label>

                                        <div class="col-md-4">
                                            <g:textField class="form-control" type="text" name="code" id="label1"
                                                         value=""/>
                                        </div>
                                    </div>

                                </div>

                                <div class="modal-footer">
                                    <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                                    <button type="button" class="btn btn-primary" id="submit1">确定</button>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    %{--弹框2--}%
    <div class="content animate-panel p-b-n">
        <div class="row">
            <div class="hpanel">
                <div class="modal fade hmodal-info" id="add2" tabindex="-1" role="dialog" aria-hidden="true">
                    <div class="modal-dialog">
                        <div class="modal-content">
                            <div class="color-line"></div>

                            <div class="modal-header">
                                <h4 class="modal-title"><span id="title2">添加二级参数</span><small style="font-size: 14px"
                                                                                              class="font-bold">(注：<span
                                            style="color: red">*</span> 为必填)</small></h4>
                            </div>

                            <form action="save" class="form-horizontal" name="add2" id="add2form">
                                <div class="modal-body form-horizontal">

                                    <input type="hidden" name="id" id="id2" value="">

                                    <div class="form-group">
                                        <label class="col-md-2 control-label is-required">标签</label>

                                        <div class="col-md-4">
                                            <g:textField class="form-control" type="text" name="label" id="label2"
                                                         value=""/>
                                        </div>

                                        <label class="col-md-2 control-label is-required">排序</label>

                                        <div class="col-md-4">
                                            <g:textField class="form-control" type="text" name="orderNumber"
                                                         id="order2" value=""/>
                                        </div>
                                    </div>

                                    <div class="form-group">
                                        <label class="col-md-2 control-label is-required">最小值</label>

                                        <div class="col-md-4">
                                            <g:textField class="form-control" type="text" name="minValue" id="min2"
                                                         value=""/>
                                        </div>

                                        <label class="col-md-2 control-label is-required">最小值操作符</label>

                                        <select class="col-md-4 form-control form-group" name="minOperator"
                                                id="minoperator2" style="width: 28.5%;margin-left: 2.5%;">
                                            <option value="1">></option>
                                            <option value="2">>=</option>
                                            <option value="3">=</option>
                                            <option value="4"><</option>
                                            <option value="5"><=</option>
                                        </select>
                                    </div>

                                    <div class="form-group">

                                        <label class="col-md-2 control-label is-required">最大值</label>

                                        <div class="col-md-4">
                                            <g:textField class="form-control" type="text" name="maxValue" id="max2"/>
                                        </div>

                                        <label class="col-md-2 control-label is-required">最大值操作符</label>

                                        <select class="col-md-4 form-control form-group" name="maxOperator"
                                                id="maxoperator2" style="width: 28.5%;margin-left: 2.5%;">
                                            <option value="1">></option>
                                            <option value="2">>=</option>
                                            <option value="3">=</option>
                                            <option value="4"><</option>
                                            <option value="5"><=</option>
                                        </select>

                                    </div>

                                    <div class="form-group">
                                        <label class="col-md-2 control-label is-required">定义</label>

                                        <div class="col-md-4">
                                            <g:textField class="form-control" type="text" name="define" id="define"
                                                         value=""/>
                                        </div>
                                    </div>
                                </div>

                                <div class="modal-footer">
                                    <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                                    <button type="button" class="btn btn-primary" id="submit2">确定</button>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    %{--弹框3--}%
    <div class="content animate-panel p-b-n">
        <div class="row">
            <div class="hpanel">
                <div class="modal fade hmodal-info" id="upd1" tabindex="-1" role="dialog" aria-hidden="true">
                    <div class="modal-dialog">
                        <div class="modal-content">
                            <div class="color-line"></div>

                            <div class="modal-header">
                                <h4 class="modal-title"><span id="titleu1">修改一级参数</span><small style="font-size: 14px"
                                                                                               class="font-bold">(注：<span
                                            style="color: red">*</span> 为必填)</small></h4>
                            </div>

                            <form action="save" class="form-horizontal" name="upd1" id="upd1from">
                                <div class="modal-body form-horizontal">

                                    <input type="hidden" name="id" id="modifyid" value="">

                                    <div class="form-group">
                                        <label class="col-md-2 control-label is-required">标签</label>

                                        <div class="col-md-4">
                                            <g:textField class="form-control" type="text" name="label" id="labeul"/>
                                        </div>

                                        <label class="col-md-2 control-label is-required">排序</label>

                                        <div class="col-md-4">
                                            <g:textField class="form-control" type="text" name="orderNumber"
                                                         id="orderu1"/>
                                        </div>
                                    </div>

                                    <div class="form-group">
                                        <label class="col-md-2 control-label is-required">唯一代码</label>

                                        <div class="col-md-4">
                                            <g:textField class="form-control" type="text" name="code" id="code1"
                                                         value=""/>
                                        </div>
                                    </div>

                                </div>

                                <div class="modal-footer">
                                    <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                                    <button type="button" class="btn btn-primary" id="submitu1">确定</button>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    %{--弹框4--}%
    <div class="content animate-panel p-b-n">
        <div class="row">
            <div class="hpanel">
                <div class="modal fade hmodal-info" id="upd2" tabindex="-1" role="dialog" aria-hidden="true">
                    <div class="modal-dialog">
                        <div class="modal-content">
                            <div class="color-line"></div>

                            <div class="modal-header">
                                <h4 class="modal-title"><span id="titleu2">修改二级参数</span><small style="font-size: 14px"
                                                                                               class="font-bold">(注：<span
                                            style="color: red">*</span> 为必填)</small></h4>
                            </div>

                            <form action="save" class="form-horizontal" name="upd2" id="upd2from">
                                <div class="modal-body form-horizontal">

                                    <input type="hidden" name="id" id="idu2" value="">

                                    <div class="form-group">
                                        <label class="col-md-2 control-label is-required">标签</label>

                                        <div class="col-md-4">
                                            <g:textField class="form-control" type="text" name="label" id="labelu2"/>
                                        </div>

                                        <label class="col-md-2 control-label is-required">排序</label>

                                        <div class="col-md-4">
                                            <g:textField class="form-control" type="text" name="orderNumber"
                                                         id="orderu2"/>
                                        </div>
                                    </div>

                                    <div class="form-group">
                                        <label class="col-md-2 control-label is-required">最小值</label>

                                        <div class="col-md-4">
                                            <g:textField class="form-control" type="text" name="minValue" id="minu2"/>
                                        </div>

                                        <label class="col-md-2 control-label is-required">最小值操作符</label>

                                        <select class="col-md-4 form-control form-group" name="minOperator"
                                                id="minoperatoru2" style="width: 28.5%;margin-left: 2.5%;">
                                            <option value="1">></option>
                                            <option value="2">>=</option>
                                            <option value="3">=</option>
                                            <option value="4"><</option>
                                            <option value="5"><=</option>
                                        </select>
                                    </div>

                                    <div class="form-group">

                                        <label class="col-md-2 control-label is-required">最大值</label>

                                        <div class="col-md-4">
                                            <g:textField class="form-control" type="text" name="maxValue" id="maxu2"/>
                                        </div>

                                        <label class="col-md-2 control-label is-required">最大值操作符</label>

                                        <select class="col-md-4 form-control form-group" name="maxOperator"
                                                id="maxoperatoru2" style="width: 28.5%;margin-left: 2.5%;">
                                            <option value="1">></option>
                                            <option value="2">>=</option>
                                            <option value="3">=</option>
                                            <option value="4"><</option>
                                            <option value="5"><=</option>
                                        </select>

                                    </div>

                                    <div class="form-group">
                                        <label class="col-md-2 control-label is-required">定义</label>

                                        <div class="col-md-4">
                                            <g:textField class="form-control" type="text" name="define" id="define2"
                                                         value=""/>
                                        </div>
                                    </div>
                                </div>

                                <div class="modal-footer">
                                    <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                                    <button type="button" class="btn btn-primary" id="submitu2">确定</button>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>



    <g:javascript>
        $(function () {
            $('.new_btn').on('click', function () {
                // var data_id = this.attributes['data-id'].value;
                $('#id2').val($(this).attr('data-id'));
            })

            $('.estateRiskBtn').on('click', function () {
                // var data_id = this.attributes['data-id'].value;
                var sss = $(this).attr('type-dic');
                $('#dictoryType').val($(this).attr('type-dic'));
            })

            $('.reportScopeBtn').on('click', function () {
                // var data_id = this.attributes['data-id'].value;
                $('#dictoryType').val($(this).attr('type-dic'));
            })

            /*$('#tab_List li').on('click', function () {
                console.log(this.innerText);
                if (this.innerText.trim() == '报告周期') {
                    $('#ReportScope').css('display', 'block');
                    $('#EstateRisk').css('display', 'none');
                } else if (this.innerText.trim() == '押品风险') {
                    $('#ReportScope').css('display', 'none');
                    $('#EstateRisk').css('display', 'block');
                }
            })*/
        });

        $(function () {
            $('.modify_btn').on('click', function () {
                var data_id = this.attributes['data-id'].value;
                var data_label = this.attributes['data-label'].value;
                var order_number = this.attributes['order-number'].value;
                var data_code = this.attributes['data-code'].value;
                $('#modifyid').val(data_id);
                $('#labeul').val(data_label);
                $('#orderu1').val(order_number);
                $('#code1').val(data_code);
            })
        })

        $(function () {
            $('.s_modify_btn').on('click', function () {
                var data_id = this.attributes['data-id'].value;
                var data_label = this.attributes['data-label'].value;
                var order_number = this.attributes['order-number'].value;
                var minValue = this.attributes['minValue'].value;
                var maxValue = this.attributes['maxValue'].value;
                var minOperator = this.attributes['minOperator'].value;
                var maxOperator = this.attributes['maxOperator'].value;
                var define = this.attributes['define'].value;


                $('#idu2').val(data_id);
                $('#labelu2').val(data_label);
                $('#orderu2').val(order_number);
                $('#minu2').val(minValue);
                $('#maxu2').val(maxValue);
                $('#define2').val(define);
                $("#select2-chosen-3").html(minOperator)
                $("#select2-chosen-4").html(maxOperator)
                if (maxOperator == ">") {
                    maxOperator = "1"
                } else if (maxOperator == ">=") {
                    maxOperator = "2"
                } else if (maxOperator == "=") {
                    maxOperator = "3"
                } else if (maxOperator == "<") {
                    maxOperator = "4"
                } else if (maxOperator == "<=") {
                    maxOperator = "5"
                }
                if (minOperator == ">") {
                    minOperator = "1"
                } else if (minOperator == ">=") {
                    minOperator = "2"
                } else if (minOperator == "=") {
                    minOperator = "3"
                } else if (minOperator == "<") {
                    minOperator = "4"
                } else if (minOperator == "<=") {
                    minOperator = "5"
                }
                $('#minoperatoru2').val(minOperator);
                $('#maxoperatoru2').val(maxOperator);

            })
        })

        $(function () {
            //增加一级参数
            $("#submit1").click(function () {
                $.ajax({
                    url: '/customerDimension/createPrimaryDimension',
                    dataType: 'json',
                    type: 'post',
                    data: $("#add1form").serialize(),
                    success: function (data) {
                        if (data.success) {
                            alert('操作成功')
                        } else {
                            alert('操作失败')
                        }
                        window.location.reload()
                    }
                })
            })

            //增加二级参数
            $("#submit2").click(function () {
                $.ajax({
                    url: '/customerDimension/createSecondaryDimension',
                    dataType: 'json',
                    type: 'post',
                    data: $("#add2form").serialize(),
                    success: function (data) {
                        if (data.success) {
                            alert('操作成功')
                        } else {
                            alert('操作失败')
                        }
                        window.location.reload()
                    }
                })
            })

            //修改一级参数
            $("#submitu1").click(function () {
                $.ajax({
                    url: '/customerDimension/modifyPrimaryDimension',
                    dataType: 'json',
                    type: 'post',
                    data: $("#upd1from").serialize(),
                    success: function (data) {
                        if (data.success) {
                            alert('操作成功')
                        } else {
                            alert('操作失败')
                        }
                        window.location.reload()
                    }
                })
            })

            //修改二级参数
            $("#submitu2").click(function () {
                $.ajax({
                    url: '/customerDimension/modifySecondaryDimension',
                    dataType: 'json',
                    type: 'post',
                    data: $("#upd2from").serialize(),
                    success: function (data) {
                        if (data.success) {
                            alert('操作成功')
                        } else {
                            alert('操作失败')
                        }
                        window.location.reload()
                    }
                })
            })

        })

        //删除一级参数
        $('.delDimen').click(function () {
            if (window.confirm("删除一级纬度将会同时删除其子纬度，确定删除此维度?")) {

                var data_id = this.attributes['data-id'].value;
                $.ajax({
                    url: '/customerDimension/removePrimaryDimension',
                    data: {
                        id: data_id
                    },
                    type: 'post',
                    dataType: 'json',
                    success: function (data) {
                        if (data.success) {
                            alert('删除成功!')
                        } else {
                            alert('删除失败!')
                        }
                        window.location.reload()
                    }
                })
            }
        })

        //删除二级参数
        $('.s-delDimen').click(function () {
            if (window.confirm("确定删除此维度?")) {

                var data_id = this.attributes['data-id'].value;
                $.ajax({
                    url: '/customerDimension/removeSecondaryDimension',
                    data: {
                        id: data_id
                    },
                    type: 'post',
                    dataType: 'json',
                    success: function (data) {
                        if (data.success) {
                            alert('删除成功!')
                        } else {
                            alert('删除失败!')
                        }
                        window.location.reload()
                    }
                })
            }
        })

        $(function () {
            $('#goBack').click(function () {
                window.history.back(-1);
            })
        })
    </g:javascript>

</body>
</html>